package cam.School.Services;


import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import cam.School.DataAccessObject.DAOFactory;
import cam.School.DataAccessObject.UserRequestDAO;
import cam.School.DataTransfertObject.CallResult;
import cam.School.DataTransfertObject.UserRequestDTO;

//When an employee send a request to download or upload a document for a Student
@Path("/requestService")
public class RequestService {
	//ServiceMethods:
//		 -sendRequest
//		 -getRequestResponse
//		 -sendRequestResponse
//		 -sendMail
//	     -receiveMail
//		 - //new old..
//		
	@POST
	@Path("/sendRequest")
	@Produces(MediaType.APPLICATION_JSON)
	public Response sendRequest(UserRequestDTO request) {				  
		DAOFactory javabase = DAOFactory.getInstance("javabase.jdbc");
		
		UserRequestDAO requestDAO = javabase.getUserRequestDAO();       

		CallResult result = requestDAO.create(request);		
		if((new Integer((int)result.getResultCode()).equals(new Integer(404))) == false){
			return Response.status(Response.Status.OK).entity(result).build();		
		}
		return Response.status(Response.Status.UNAUTHORIZED).entity(result).build();		
	}
	
	@GET
	@Path("/sendRequestResponse?content={content}&requestId={requestId}&to={idTo}")
	@Produces(MediaType.TEXT_XML)
	public boolean sendRequestResponse(@PathParam("content") String content, @PathParam("requestId") int requestId, @PathParam("idTo") int idTo ) {				  
		//TODO 
		return true; //or false 		
	}
	
	@GET
	@Path("/getRequestResponse?requestId={requestId}")
	@Produces(MediaType.TEXT_XML)
	public boolean getRequestResponse(@PathParam("requestId")int requestId ) {				  
		//TODO 
		return true; //or false 		
	}
	
	@POST
	@Path("/sendMail?content={content}&from={from}&to={to}")
	@Produces(MediaType.TEXT_XML)
	public boolean sendMail(@PathParam("content") String content, @PathParam("from") String from, @PathParam("to") String to ) {				  
		//TODO 
		return true; //or false 		
	}
	
	@GET
	@Path("/receiveMail?content={content}&from={from}")
	@Produces(MediaType.TEXT_XML)
	public String receiveMail(@PathParam("from")String from ) {				  
		//TODO 
		return ""; //		
	}

}
